﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;

namespace DailyComics.Common.Model.Storage
{
  public class ImageMemoryStorage : IStorage
  {
    private Dictionary<DateTime, ImageSource> cache = new Dictionary<DateTime, ImageSource>();

    #region IStorage Members

    public void Set(DateTime date, ImageSource img)
    {
      if (!Contains(date)) cache.Add(date, img);
    }

    public ImageSource Get(DateTime date)
    {
      return cache[date];
    }

    public bool TryGet(DateTime date, out ImageSource img)
    {
      img = null;

      if (!Contains(date)) return false;

      img = cache[date];

      return true;
    }

    public bool Contains(DateTime date)
    {
      return cache.ContainsKey(date);
    }

    #endregion
  }
}
